﻿using IMES.Common.Domain.KeepModel.Process;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;
using System.ComponentModel;

namespace Keep.API.Appliction.Command.ProcessFile
{
    /// <summary>
    /// 处理工艺类型列表命令处理器
    /// </summary>
    public class WTypeListHandler:IRequestHandler<WTypeListCommon,Result>
    {
        private readonly IBaseRepositorys<WType> _wtypeRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="wtypeRep"></param>
        public WTypeListHandler(IBaseRepositorys<WType> wtypeRep)
        {
            _wtypeRep = wtypeRep;
        }

        /// <summary>
        /// 处理处理工艺类型列表命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<Result> Handle(WTypeListCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CodeEnum.success, Messege = "获取工艺类型列表成功" };
            try
            {
                var wtypes = _wtypeRep.GetAll().ToList();
                if (wtypes.Count == 0)
                {
                    result.Code = (int)CodeEnum.search;
                    result.Messege = "暂无数据";
                    return Task.FromResult(result);
                }
                else
                {
                    result.Data = wtypes;
                } 
            }
            catch (Exception ex)
            {
                result.Code = (int)CodeEnum.error;
                result.Messege = ex.Message;
            }
            return Task.FromResult(result);
        }
    }
}
